<?php
class Merchant_Model_User
{

	private $_table;
	//Initalizing Db Table  
	public function Merchant_Model_User(){
		$this->_table = new Merchant_Model_DbTable_User();
	}
	
	
	public function getByUserId($userId){	
		$select = $this->_table->select()->where('user_id = ?', $userId);	 
		return $this->_table->fetchRow($select);		
	}
	
	/**
	*Get Rowset By Department Name
	*@param string $ud_id 部门id
	*@return Rowset
	*/
	public function getByName($departmentName){
	
		$select = $this->_table->select()->where('ud_name = ?', $departmentName);	 
		
		return $this->_table->fetchRow($select);
		
	}
	
	/**
	*Get Rowset By user 
	*@param string $ud_id login id
	*@return Rowset
	*/
	public function getByLoginId($id){
		$select = $this->_table->select()->where('login_id = ?', $id);	 
		return $this->_table->fetchRow($select);
	}
	
	/*
	*get List
	*/
	public function getList($cond,$type='*' ,$order='user_id', $offset =0, $pageSize=0){	

		$select = $this->_table->getAdapter()->select();
        $table = $this->_table->info('name');
		if($type!='*') $type= 'count(*)';
        $select->from($table,$type);
        
		if(@$cond['ud_id']){
			$select->where('ud_id = ?', $cond['ud_id']);
		}
		if(isset($cond['status']) && $cond['status'] !==''){
			$select->where('status = ?', $cond['status']);
		}
		if(isset($cond['login_id']) && $cond['login_id'] !=''){
			$select->where('login_id = ?', $cond['login_id']);
		}
		
		if(isset($orderby)) $select->order($orderby);
		if($pageSize>0 and $offset>=0){			
			$select->limit($pageSize,$offset);
		}
		if($type=='*'){
			return $this->_table->getAdapter()->fetchAll($select->__toString());
		}else {
			return $this->_table->getAdapter()->fetchOne($select->__toString());
		}
		
	}
	
}